package com.ttscm.srds.pojo;

import java.io.Serializable;

/**
 * @version:
 * @author:
 * @className:
 * @packageName:
 * @description:
 * @date: 2022/07/23
 */
public class ResponseResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private Integer code;
    private String message;
    private T data;

    public static <T> ResponseResult<T> succeed() {
        return response(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(), null);
    }

    public static <T> ResponseResult<T> succeed(T data) {
        return response(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(), data);
    }

    public static <T> ResponseResult<T> fail() {
        return response(ResponseEnum.ERROR.getCode(), ResponseEnum.ERROR.getMessage(), null);
    }

    public static <T> ResponseResult<T> fail(Integer code, String message) {
        return response(code, message, null);
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    private static <T> ResponseResult<T> response(int code, String message, T data) {
        return new ResponseResult<>(code, message, data);
    }

    private ResponseResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
